import { getBanner } from "@/api/banner";
import { rver_URL } from "@/urlConfig.js";

export default {
  namespaced: true,
  state: {
    loading: false,
    data: [],
  },
  mutations: {
    setLoading(state, payloda) {
      state.loading = payloda;
    },
    setData(state, payloda) {
      state.data = payloda;
    }
  },
  actions: {
    async fetchBanner({commit, state}) {
      if(state.data.length) {
        return;
      }
      commit("setLoading", true);
      const resp = await getBanner();
      for (const item of resp) {
        item.midImg2 = rver_URL + item.midImg;
        item.bigImg2 = rver_URL + item.bigImg;
      }
      commit("setData", resp);
      commit("setLoading", false);
    }
  }
}